package net.zhnb.listener;

import java.math.BigDecimal;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import net.zhnb.bean.Global;
import net.zhnb.bean.GlobalKey;
import net.zhnb.service.GlobalService;

import org.springframework.web.context.support.WebApplicationContextUtils;

public class ProjectListener implements ServletContextListener {
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		try {
			GlobalService globalService =(GlobalService) WebApplicationContextUtils.
					getRequiredWebApplicationContext(sce.getServletContext()).getBean ("globalService");
			Global global = globalService.findByKey(new GlobalKey(new BigDecimal("1")));
			if(global==null){
				global = new Global();
				global.setId(new BigDecimal("1"));
				global.setLotterynum(new BigDecimal("6"));
				global.setLotterylun(new BigDecimal("3"));
				global.setLotterypersent1(new BigDecimal("25"));
				global.setLotterypersent2(new BigDecimal("25"));
				global.setLotterypersent3(new BigDecimal("25"));
				global.setSystemweibo("@宁波智慧车展");
				globalService.insert(global);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
